package com.rbcs.budget.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.rbcs.budget.service.BudgetItemtManager;

@SuppressWarnings("serial")
public class BudgetItemSumAmountTag extends BodyTagSupport {

	private Integer itemId;

	private Integer year;

	private String deptSerialNo;

	@Override
	public int doEndTag() throws JspException {
		try {
			pageContext.getOut().print(
					getBudgetItemtManager().sumItemByTopDept(itemId, year,
							deptSerialNo));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	private BudgetItemtManager getBudgetItemtManager() {
		return (BudgetItemtManager) getContext().getBean("budgetItemtManager");
	}

	private ApplicationContext getContext() {
		return WebApplicationContextUtils.getWebApplicationContext(pageContext
				.getServletContext());

	}

	public Integer getItemId() {
		return itemId;
	}

	public void setItemId(Integer itemId) {
		this.itemId = itemId;
	}

	public String getDeptSerialNo() {
		return deptSerialNo;
	}

	public void setDeptSerialNo(String deptSerialNo) {
		this.deptSerialNo = deptSerialNo;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

}
